home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A).zip / Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A).po / UNPACK.S < prev   
Text File  |  1996-12-24  |  6KB  |  180 lines

  1. *------------------------------ *
  2. *  Universal Super Res picture  *
  3. *  unpacker by Peter  Stubbs    *
  4. *-------------------------------*
  5. *   MERLIN 816 ASSEMBLER        *
  6. *-------------------------------*
  7. *       Copyright (C) 1991      *
  8. *      MindCraft Publ. Corp.    *
  9. *-------------------------------*
  10. *--------------------------------------------------
  11. * Unpacks pictures packed with PAINTWORKS PLUS,
  12. * DELUXEPAINT and PackBytes (from TOOL BOX)
  13. *
  14. *         PLEASE NOTE:
  15. *         -----------
  16. * 1. Can tell packed pic type from the AUX ID
  17. *
  18. *    If AUX ID = 0 then is in PAINTWORKS PLUS format
  19. *    If AUX ID = 1 then is in PackBytes format
  20. *    If AUX ID = 2 then is in DELUXE PAINT format
  21. *
  22. * 2. The DELUXE PAINT format is also called APPLE
  23. *    PREFERRED format
  24. *
  25. * 3. Store AUX ID at PICTYPE before unpacking
  26. *
  27. * 4. To find AUX ID from BASIC do the following:-
  28. *
  29. *     a). BLOAD UNPACK
  30. *     b). BLOAD <picname>,A$1400,T$C0
  31. *     c). CALL 942 (does a GET_FILE_INFO call)
  32. *     d). PEEK (957) gives the AUX ID
  33. *     e). If PEEK (970) <>0 it is ProDOS error code
  34. *--------------------------------------------------
  35.  
  36.           ORG $300
  37.           TR ADR
  38. LINSAVE   EQU $3         ;To hold value at NEWVIDEO
  39. SIZEPTR   EQU $4         ;Size of SuperRes pic
  40. STARTPTR  EQU $7         ;Ptr to start of pic
  41. BUFFADR   EQU $CE        ;Bank 0 buffer start addr
  42. NUMBYTES  EQU $ED        ;Number of bytes packed
  43. NEWVIDEO  EQU $C029
  44. PICTYPE   EQU $FE
  45.  
  46. SIZE      EQU $9400-$1400 ;Max size of packed pic
  47.  
  48. SETUP     LDA $C029
  49.           STA LINSAVE    ;Save for later
  50.           ORA #%01000000 ;Linear  mode on
  51.           STA $C029
  52.           LDA PICTYPE
  53.           BEQ PNTUNPAK   ;PAINTWORKS format
  54.           CMP #$2        ;DELUXEPAINT format
  55.           BEQ DLXUNPAK
  56.           CMP #$1        ;PackBytes format
  57.           BNE EXIT       ;Do nothing
  58.           JSR NATIVE     ;NATIVE MODE
  59.  
  60. * Set up values to unpack the picture
  61.  
  62.           MX %00
  63.           LDY #$0000     ;Buffer offset of zero
  64. UNPAK     LDA #$A000-$2000 ;Size of area to unpack
  65.  
  66. * Entry point for PAINTWORKS and DELUXEPAINT unpack
  67.  
  68. UNPAK2    STA SIZEPTR
  69.           STZ SIZEPTR+2  ;Zero high part of ptr
  70.           LDA #$E12000   ;Address of start of pic
  71.           STA STARTPTR
  72.           LDA #^$E12000
  73.           STA STARTPTR+2
  74.           TYA            ;Move buffer offset to acc
  75.           CLC            ;prepare to add $1400 to
  76.           ADC #$1400     ;get start address of data
  77.           STA BUFFADR    ;and save for unpack code
  78.  
  79. * Now do the unpack
  80.  
  81.           MX %00
  82.           PEA $0000      ;Space for result
  83.           PEA $0000      ;HI addr of BUFFER
  84.           LDA BUFFADR    ;Get LO addr of BUFFER
  85.           PHA            ; and put on stack
  86.           PEA #<SIZE     ;Max size of pack buffer
  87.           PEA #^STARTPTR ;Pointer to word with start
  88.           PEA #<STARTPTR ; of area to unpack
  89.           PEA #^SIZEPTR  ;Pointer to word with size
  90.           PEA SIZEPTR    ; of area to unpack
  91.           LDX #$2703     ;_UnpackBytes tool call
  92.           JSL $E10000    ;Call the Tool Locator
  93.           PLA            ;Discard no. bytes unpacked
  94. EXIT      JSR EMMODE     ;EMULATION MODE ON
  95.           RTS            ;Exit
  96.  
  97. * PAINTWORKS PLUS Unpack setup
  98.  
  99.           MX %11
  100. PNTUNPAK  STZ LOOP+1     ;Make start of palette data
  101.           JSR MOVEPAL    ; $1400 then move it across
  102.           STZ $1409      ;Flag as 320 mode
  103.           LDA #$02       ;Paintworks packed pic data
  104.           PHA            ; is offset $222 bytes from
  105.           LDA #$22       ; the start of the buffer
  106.           PHA            ;Note these are 8 bit PHA's
  107.           BRA COMMON     ;Go to common unpack code
  108.  
  109. * DELUXE PAINT Unpack setup
  110.  
  111. DLXUNPAK  LDA #$0F       ;Pal. data starts at $140F
  112.           STA LOOP+1     ; so patch pal. start addr.
  113.           JSR MOVEPAL    ; then move the palette
  114.           LDA #$03       ;Deluxepaint packed data
  115.           PHA            ; is offset $351 bytes from
  116.           LDA #$51       ; the start of the buffer
  117.           PHA            ;Note these are 8 bit PHA's
  118.  
  119. * CHANGE ALL POINTERS TO POINT AT PALETTE 0
  120.  
  121. COMMON    CLC            ;Start with zero in carry
  122.           LDA $1409      ;Check for 320 or 640 mode
  123.           BPL NORM       ;If 320 mode we're done
  124.           SEC            ;Put 1 in Carry for 640
  125. NORM      LDX #$0
  126.           TXA            ;Start with SCB of zero
  127.           ROR            ;Sets SCB = $80 if carry set
  128. MORE      STAL $E19D00,X ;Set palette zero and
  129.           INX            ; correct res mode in SCB's
  130.           BNE MORE
  131.           MX %00
  132.           JSR NATIVE     ;Then do a 16 bit PLY
  133.           PLY            ;Y=$222 or $351 offset
  134.           LDA #$9D00-$2000 ;Size of area to unpack
  135.           BRA UNPAK2     ;Go unpack the picture
  136.  
  137. * MOVE PALETTE ACROSS - USED BY DLXUNPAK & PNTUNPAK
  138.  
  139.           MX %11
  140. MOVEPAL   LDX #$00
  141. LOOP      LDA $1400,X    ;Patched by caller
  142.           STAL $E19E00,X
  143.           INX
  144.           CPX #$21
  145.           BNE LOOP
  146.           RTS
  147.           MX %00
  148. NATIVE    CLC            ;NATIVE MODE ON
  149.           XCE
  150.           REP #$30
  151.           RTS
  152. EMMODE    SEC            ;EMULATION MODE ON
  153.           XCE
  154.           MX %11
  155.           LDA LINSAVE
  156.           STA $C029
  157.           RTS
  158.  
  159. * Code to do a GET_FILE_INFO to find AUX ID
  160.  
  161. INFO      JSR $BF00      ;Call ProDOS MLI
  162.           DFB $C4        ;Get file info value
  163.           DA PARMS       ;Address of paramters
  164.           STA ERR        ;A=0 If no error
  165.           RTS
  166.  
  167. PARMS     DFB $A         ;No. of parameters
  168. PATHNAME  DA $280        ;ProDOS pathname buffer
  169. ACCESS    DS 1
  170. TYPE      DS 1
  171. AUXTYPE   DS 2           ;AUX ID
  172. STORAGE   DS 1
  173. USED      DS 2
  174. MODDATE   DS 2
  175. MODTIME   DS 2
  176. CREDATE   DS 2
  177. CRETIME   DS 2
  178. ERR       DS 1           ;ProDOS error code
  179.           LST OFF
  180.